#
# @lc app=leetcode.cn id=435 lang=python
#
# [435] 无重叠区间
#

# @lc code=start
class Solution(object):
    def eraseOverlapIntervals(self, intervals):
        """
        :type intervals: List[List[int]]
        :rtype: int
        """
        erase = 0
        intervals.sort(key=lambda x: (x[0], x[1]))
        end = intervals[0][1]
        for i in range(1, len(intervals)):
            if intervals[i][0] < end:
                erase += 1
                end = min(intervals[i][1], end)
            else:
                end = intervals[i][1]
        return erase
        
        
# @lc code=end

